<?php
session_start();

include("config.php");

$form = 1;

if(isset($_POST['pseudo_log']) && isset($_POST['password_log']))
{

	$pseudo = $_POST['pseudo_log'];
	$password = sha1($_POST['password_log']);


	$link = mysql_connect ('localhost', DB_USER_NAME, DB_PASSWORD) or die ("Cannot join database");
	mysql_select_db (DB_NAME);

	$requete = "SELECT * FROM user WHERE pseudo='" . $pseudo . "' AND password='" . $password . "'";
	$result = mysql_query ($requete);

	if(mysql_result($result, 0) == 0)
	{
		echo "<script language=javascript>alert('User or password not valid')</script>";
	}
	else
	{
		echo "<script language=javascript>alert('Connexion succeed')</script>";
		$_SESSION['pseudo'] = $pseudo;	
		$form = 0;	
		echo '<meta http-equiv="refresh" content="0;URL=index.php">';
	}

}

mysql_close($link);



if($form)
{
?>
	<form method="post" action="index.php">
	<input class=login type="text" class="champ" name="pseudo_log" placeholder="Pseudo"/>
	<input class=login type="password" name="password_log" placeholder="Password"/>
	<input class=button type="submit" value="Valider" />
	</form>
<?
}
?>
	

